package com.example.controller;

import com.example.annotation.MasterRoute;
import com.example.entity.User;
import com.example.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserMapper userMapper;

    @GetMapping("/save")
    public String insert() {
        User user = new User();
        user.setNickname("");
        user.setPassword("123456");
        user.setSex(1);
        user.setBirthday("1990-10-01");
        userMapper.addUser(user);
        return "success";
    }

    @GetMapping("/getByRead")
    public List<User> listUserByReadDataSource() {
        return userMapper.findUsers();
    }

    @GetMapping("/getByWrite")
    @MasterRoute()
    public List<User> listUserByWriteDataSource() {
        return userMapper.findUsers();
    }


}
